<template>
    <div>
        <el-card class="!border-none" v-loading="pager.loading" shadow="never">
            <!-- <el-button v-perms="['order/add']" type="primary" @click="handleAdd">
                <template #icon>
                    <icon name="el-icon-Plus" />
                </template>
                新增
            </el-button>
            <el-button
                v-perms="['order/delete']"
                :disabled="!selectData.length"
                @click="handleDelete(selectData)"
            >
                删除
            </el-button> -->
            <div class="mt-4">
                <el-table :data="pager.lists" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55" />
                    <el-table-column label="订单编号" prop="sn" show-overflow-tooltip />
                    <el-table-column label="酒店名称" prop="hotel_title" show-overflow-tooltip />
                    <el-table-column label="房间名称" prop="room_name" show-overflow-tooltip />
                    <el-table-column label="房间数" prop="number" show-overflow-tooltip />
                    <!-- <el-table-column label="用户id" prop="user_id" show-overflow-tooltip /> -->
                    <!-- <el-table-column label="支付编号-冗余字段，针对微信同一主体不同客户端支付需用不同订单号预留。" prop="pay_sn" show-overflow-tooltip /> -->
                    <!-- <el-table-column label="支付方式 2-微信支付 3-支付宝支付" prop="pay_way" show-overflow-tooltip /> -->
                    <!-- <el-table-column label="支付状态"  show-overflow-tooltip >
                        <template #default="scope">
                            <div v-if="scope.row.pay_status == 0">待支付</div>
                            <div v-if="scope.row.pay_status == 1">已支付</div>
                            <div v-if="scope.row.pay_status == 2">已取消</div>
                        </template>
                    </el-table-column> -->
                    <!-- <el-table-column label="支付时间" prop="pay_time" show-overflow-tooltip /> -->
                    <el-table-column label="支付金额" prop="order_amount" show-overflow-tooltip />
                    <!-- <el-table-column label="终端" prop="order_terminal" show-overflow-tooltip /> -->
                    <!-- <el-table-column label="第三方平台交易流水号" prop="transaction_id" show-overflow-tooltip /> -->
                    <!-- <el-table-column label="退款状态" show-overflow-tooltip >
                        <template #default="scope">
                            <div v-if="scope.row.refund_status == 0">未退款</div>
                            <div v-if="scope.row.refund_status == 1">已退款</div>
                        </template>
                    </el-table-column> -->
                    <!-- <el-table-column label="退款交易流水号" prop="refund_transaction_id" show-overflow-tooltip /> -->
                    
                    <!-- <el-table-column label="天数" prop="day" show-overflow-tooltip /> -->
                    <el-table-column label="预定开始时间" prop="start_time" show-overflow-tooltip />
                    <el-table-column label="预定结束时间" prop="end_time" show-overflow-tooltip />
                    <el-table-column label="联系手机号" prop="phone" show-overflow-tooltip />
                    <el-table-column label="联系人" prop="name" show-overflow-tooltip />
                    <el-table-column label="订单状态" prop="status_txt" show-overflow-tooltip />

                    <el-table-column label="操作" width="80" fixed="right">
                        <template #default="{ row }">
                             <!-- <el-button
                                v-perms="['order/edit']"
                                type="primary"
                                link
                                @click="handleEdit(row)"
                            >
                                编辑
                            </el-button> -->
                            <el-button
                                v-perms="['order/delete']"
                                type="danger"
                                link
                                @click="handleSend(row)"
                            >
                                发货
                            </el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="flex mt-4 justify-end">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>

<script lang="ts" setup name="orderLists">
import { usePaging } from '@/hooks/usePaging'
import { useDictData } from '@/hooks/useDictOptions'
import { orderList, orderSend } from '@/api/order'
import { timeFormat } from '@/utils/util'
import feedback from '@/utils/feedback'

// 是否显示编辑框


// 查询条件


// 选中数据
const selectData = ref<any[]>([])

// 表格选择后回调事件
const handleSelectionChange = (val: any[]) => {
    selectData.value = val.map(({ id }) => id)
}

// 获取字典数据
const { dictData } = useDictData('')

// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: orderList,
    params: {}
})





// 发货
const handleSend = async (row: any) => {
    if (row.is_disable_refund == 1 && row.refund_status == 0) {
        const dialog = await feedback.formDialog({
            title: '请输入退款金额',
            formItems: [
                {
                    label: '退款金额',
                    prop: 'refund_amount',
                    type: 'input',
                }
            ],
            width: '460px',
            onSubmit: async (formData: any) => {
                try {
                    const res = await orderSend({ order_id: row.id, delivery_company: 1, delivery_no: 1 })
                    if(res.code == 1){
                        feedback.msgSuccess('发货成功')
                        dialog.close()
                        getLists()
                    }else{
                        feedback.msgError(res.msg)
                        dialog.close()
                    }
                } catch (error) {
                    feedback.msgError('发货失败')
                    dialog.close()
                }
            },
            onCancel: () => {
                dialog.close()
            }
        })
    } else {
        feedback.msg('该订单不支持发货')
    }
}

getLists()


onMounted(async () => {
})
</script>

